package com.haiyi.test.demo;

import javafx.application.Application;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;
import org.springframework.core.io.Resource;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;
import test.TestService;

import java.util.Scanner;

@SpringBootApplication
@ServletComponentScan
@EnableScheduling
@EnableAsync
//@ComponentScan()
//@ImportResource(locations = "classpath:/com/a.properties")
public class DemoApplication {

	@Bean(value="config")
	public ConfigBean get(){
		ConfigBean bean = new ConfigBean();
		bean.setId("id");
		return bean;
	}


	public static ApplicationContext context;

	public static void main(String[] args) throws Exception{
		String[] arg = new String[]{"--xx1=234"};
		ApplicationContext ac = SpringApplication.run(DemoApplication.class, args);
		//Object o = ac.getBean("impl");
		context = ac;
		System.out.println("");
		Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
			@Override
			public void run() {
               System.out.println("shutdown");
			}
		}));
		// 生成获取控制台输入信息对象
		Scanner scanner = new Scanner(System.in);

		// 循环
		while(true){
			//获取控制台输入，如果没有会被阻塞
			String in = scanner.nextLine();
			//如果输入 q表示退出程序
			if(in.equals("q")){
				break;
			}
		}
		// 退出 spring boot
		SpringApplication.exit(ac);

	}

}
